#pragma once
#ifndef BASEOBJECT_H_
#define BASEOBJECT_H_

#include "commoninclude.h"
#include "classes.h"

namespace EPOC
{
	/**
	* Base class
	* This class the base class of all EPOC classes
	*/
	class BaseObject
	{
	public:
		/**
		* Contructor
		* Resets all members to the default values
		*/
		BaseObject();

		/**
		* Destructor
		* Calls the cleanup method.
		* @see Cleanup()
		*/
		virtual ~BaseObject();

		/**
		* Updates class data
		* @remark This function is called once per frame.
		* @param fTimeDelta the time that has passed since last update, measured in milliseconds
		* @return true if the update succeeded and false if it didn't
		*/
		virtual bool Update(float fTimeDelta)		{ UNREFERENCED_PARAMETER(fTimeDelta); return true;}

		/**
		* Callback for handling SDL event
		* @remark This method is called when SDL events occurs if the class is registered to recieve events
		* @param pEvent the SDL event that occured
		*/
		virtual void HandleEvent(SDL_Event *pEvent) { UNREFERENCED_PARAMETER(pEvent); }

		/**
		* Helper method for setting class ID to identify the class
		* @param nID the class ID to set.
		* @see EP_CLASSID
		*/
		inline void SetClassID(int nID)			{ m_nID = nID;}

		/**
		* Helper method for setting class sub ID to identify the class. Sub ID's are not enumerated in EPOC. You should define your own.
		* @param nSubID the class ID to set.
		* @see EP_CLASSID
		*/
		inline void SetClassSubID(int nSubID)	{ m_nSubID = nSubID;}

		/**
		* Helper method for getting the class ID of the class
		* @return the class ID of the class
		*/
		inline int GetClassID()					{ return m_nID;}

		/**
		* Helper method for getting the class sub ID of the class
		* @return the class ID of the class
		*/
		inline int GetClassSubID()				{ return m_nSubID;}

		/**
		* Helper method for getting the reference count of the class
		* @return the reference count of the class
		*/
		inline int GetRefCount()				{ return m_nRefCounter;}
		
		/**
		* Method for adding a reference to the class
		* @see GetRefCount
		* @see Release
		*/
		inline void AddRef()					{ m_nRefCounter++;}

		/**
		* Method for releasing a reference to the class. Once the reference count gets below one this method deletes the this object
		* @see GetRefCount
		* @see AddRef
		*/
		inline void Release()					{ if(--m_nRefCounter <= 0) delete this;}

		/**
		* Helper method checking the class ID. 
		* @return true if the class is of the same ID as the parameter
		*/
		bool IsClass(int nID)					{ if(m_nID == nID) return true; return false;}
		
		/**
		* Helper method for getting the reference count of the class
		* @return the reference count of the class
		*/
		bool IsSubClass(int nSubID)				{ if(m_nSubID == nSubID) return true; return false;}
		
	protected:
		int m_nID;
		int m_nSubID;
		int m_nRefCounter;
	
	}; // class BaseObject
}; // namespace EPOC

#endif